//
//  HMLoginMainViewController.m
//  获得
//
//  Created by mac on 17/1/6.
//  Copyright © 2017年 mac.gu. All rights reserved.
//

#import "HMLoginMainViewController.h"
#import "HMPhoneNumSignInViewController.h"
#import "UIViewController+Extension.h"
#import "HMPhoneNumLoginViewController.h"
@interface HMLoginMainViewController ()

@end

@implementation HMLoginMainViewController{
    UIButton *_wechatBtn;
    UIButton *_loginBtn;
    UIButton *_singInBtn;
    UIButton *_exitBtn;
    HMPhoneNumLoginViewController *_loginVC;
    HMPhoneNumSignInViewController *_signInVC;
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    _loginVC.view.backgroundColor = [UIColor colorWithHex:0xffffff];
    _signInVC.view.backgroundColor = [UIColor colorWithHex:0xffffff];
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
    backItem.title = @"返回";
    self.navigationItem.backBarButtonItem = backItem;

    
    //设置view背景图片
    self.view.layer.contents = (__bridge id _Nullable)([UIImage imageNamed:@"force_login_bg"].CGImage);
    
    

    [self setupUI];
    
 
}

- (void)setupUI{
    
    //微信登录按钮
    _wechatBtn = [[UIButton alloc]init];
    [_wechatBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_wechatBtn setTitle:@"微信快捷登录" forState:UIControlStateNormal];
    [_wechatBtn setBackgroundImage:[UIImage imageNamed:@"login_bg"] forState:UIControlStateNormal];
    
    [self.view addSubview:_wechatBtn];
    [_wechatBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.centerY.equalTo(self.view).offset(-50);
        make.height.offset(50);
        make.width.offset(260);
    }];
    [_wechatBtn addTarget:self action:@selector(wechatBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    
    // 手机登录      //手机注册
    NSArray *titleArray = @[@"手机登录",@"手机注册"];
    //创建分类按钮
    NSMutableArray *buttonArrM = [NSMutableArray arrayWithCapacity:2];
    
    for (NSInteger i = 0; i < titleArray.count; i++) {
        
        UIButton *titleButton = [[UIButton alloc]init];
        [titleButton setTitle:titleArray[i] forState:UIControlStateNormal];
        
        [titleButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        titleButton.titleLabel.font = [UIFont systemFontOfSize:14];
        
        //给button设置tag
        titleButton.tag = i;
        
        
        [titleButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [titleButton setBackgroundImage:[UIImage imageNamed:@"main_pop_bg_210x70_"] forState:UIControlStateNormal];
        [titleButton setBackgroundImage:[UIImage imageNamed:@"main_pop_bg_210x70_"] forState:UIControlStateHighlighted];
        [self.view addSubview:titleButton];
        
        [buttonArrM addObject:titleButton];
        
    }
    
    //设置按钮的约束
    [buttonArrM mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:0 leadSpacing:0 tailSpacing:0];
    
    [buttonArrM mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_wechatBtn.mas_bottom).offset(10);
        make.height.offset(80);
    }];
    
    // X 按钮
    _exitBtn = [[UIButton alloc]init];

    
    [_exitBtn setBackgroundImage:[UIImage imageNamed:@"gift_horizontal_dismiss_btn_44x44_"] forState:UIControlStateNormal];

    [self.view addSubview:_exitBtn];
    [_exitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(_wechatBtn.mas_bottom).offset(200);
    }];
    [_exitBtn addTarget:self action:@selector(exitBtnBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    
}

//微信登录按钮
- (void)wechatBtnClick{
    
    [self showHudAuto:@"没给微信付费,不能使用微信登录" andDuration:@"3"];
    [[HMNetWorkTool sharedTool]getUserInfoForPlatform:1];
    
    
}

// 登录 按钮 点击事件
- (void)buttonClick:(UIButton *)sender{
    if (sender.tag == 0) {
        //手机登录
        
        _loginVC = [[HMPhoneNumLoginViewController alloc]init];
        self.view.backgroundColor = [UIColor colorWithHex:0xffffff];

        [self.navigationController pushViewController:_loginVC animated:YES];

        
    }else if (sender.tag == 1){
        //手机注册
        
        _signInVC = [[HMPhoneNumSignInViewController alloc]init];
        self.view.backgroundColor = [UIColor colorWithHex:0xffffff];
        
        [self.navigationController pushViewController:_signInVC animated:YES];
        
    }
    
    
}

//退出按钮点击事件
- (void)exitBtnBtnClick{
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)keng{
    
}

@end
